Skip to content

Conversation

ganesh-karande
Copy link

This PR introduces an implementation of the IntroSort (Introspective Sort) algorithm in C++ as a new sorting method under sorting/intro_sort.cpp.

IntroSort is a hybrid sorting algorithm combining QuickSort, HeapSort, and InsertionSort to achieve both fast average-case performance and optimal worst-case guarantees. It starts with QuickSort, switches to HeapSort when recursion depth exceeds a limit (2 * log₂(n)), and uses InsertionSort for small partitions (≤ 16 elements).

The implementation includes:

  • QuickSort base with Lomuto partition scheme
  • Depth-limit detection to switch to HeapSort and avoid QuickSort’s worst-case
  • InsertionSort for small subarrays to optimize performance
  • Comments explaining time and space complexity
  • Sample test cases in main() to verify correctness on various inputs (best, average, worst cases)

This addition enhances the repository by providing a practical, industrial-strength sorting algorithm, complements existing sorting algorithms, and serves as an educational reference for hybrid sorting strategies.

Closes #3010.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add IntroSort Algorithm in C++
1 participant